
function load_all(key, order){
    var url = '';
    var company_id = $("#company_id").val();
    if(key == 0) url = SITE_URL + '/receipts/load_all';
    else if(key == 1) url = SITE_URL + '/receipts/load_enroll';
    else if(key == 2) url = SITE_URL + '/receipts/load_withdraw';

    $.ajax({
        type: 'POST',
        url: url,
        data: 'key='+key+'&order='+order+'&company_id='+company_id,
        success: function(data){
            $("#the_content").html(data).fadeIn();
        }
    });
}

function load_class(id, order, key){
    var company_id = $("#company_id").val();
    url = SITE_URL + '/receipts/load_class';
    $.ajax({
        type: 'POST',
        url: url,
        data: 'key='+key+'&order='+order+'&company_id='+company_id+'&id='+id,
        success: function(data){
            $("#the_content").html(data).fadeIn();
        }
    });
}

function load_program(id, order, key){
    var company_id = $("#company_id").val();
    url = SITE_URL + '/receipts/load_program' ;
    $.ajax({
        type: 'POST',
        url: url,
        data: 'key='+key+'&order='+order+'&company_id='+company_id+'&id='+id,
        success: function(data){
            $("#the_content").html(data).fadeIn();
        }
    });
}

function receipts_all(key, order){
    var url = '';
    if(key == 0) url = SITE_URL + '/receipts/receipts_all';
    else if(key == 1) url = SITE_URL + '/receipts/receipts_valid';
    else if(key == 2) url = SITE_URL + '/receipts/receipts_void';
    $.ajax({
        type: 'POST',
        url: url,
        data: 'key='+key+'&order='+order,
        success: function(data){
            $("#the_content").html(data).fadeIn();
        }
    });
}

function receipts_yearmonth(year, month, order){
    url = SITE_URL + '/receipts/receipts_yearmonth';
    $.ajax({
        type: 'POST',
        url: url,
        data: 'order='+order+'&year='+year+'&month='+month,
        success: function(data){
            $("#the_content").html(data).fadeIn();
        }
    });
}

function validate() {
    var valid = true;
    //validations

    if(!validate_date($("#pay_date").val())){
        $("#pay_date").addClass("red");
        valid = false;
    }else{
        $("#pay_date").removeClass("red");
    }

    if(!valid){
        alert("There is some errors. Pls correct those fields in red color.");
        return false;
    }
    return true;
}

$(document).ready(function() {
    var value_void = $('.void').val();
    if(value_void == 1){
        var mytext = document.getElementById("reasons");
        mytext.focus();
    }
});

function confirmSubmit()
{
    var agree=confirm("Are you sure you want to void this receipt?");
    if (agree)
        return true ;
    else
        return false ;
}

function PrintContent(elementId)
{
//    var DocumentContainer = document.getElementById(id);
//    var WindowObject = window.open("PrintWindow", "width=670,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
//    WindowObject.document.writeln(DocumentContainer.innerHTML);
//    WindowObject.document.close();
//    WindowObject.focus();
//    WindowObject.print();
//    WindowObject.close();
    
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50,top=50,width=500,height=500');

    printWindow.document.write('<link rel="stylesheet" type="text/css" href="http://blossom.jackwoo.com/imis/css/print_style.css" />');
    printWindow.document.write(printContent.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
}

var errorValue = Array();

function isMoney(field){
    var check = true;
    var ValidChars = "0123456789.";    
    var Char;
 
    for (i = 0; i < field.value.length && check == true; i++) 
    { 
        Char = field.value.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            check = false;
            break;
        }
    }    

    if (errorValue.indexOf(field) >= 0)
    {
        errorValue[errorValue.indexOf(field)] = errorValue[0];
        errorValue.shift();
    }
    //apply appropriate colour based on value
    if(!check)
    {
        field.style.backgroundColor = "red";
        errorValue.push(field);
    }
    else
    {
        field.style.backgroundColor = "white";
    }
}
	
function checkform()
{
    if (errorValue.length >0)
    {
        alert("The input values are incorect.");
        errorValue[0].focus();
        return false;
    }
    return true;
}